$(function(){

    $("#confirm-btn").on("click",function(){
        var originPass = $("[name='originPass']").val();
        var newPass = $("[name='newPass']").val();
        var confirmPass = $("[name='confirmPass']").val();
        var vCode = $("[name='vCode']").val();

        if(!originPass){
            mui.toast("请输入原密码");
            return;
        }
        if(!newPass){
            mui.toast("请输入新密码");
            return;
        }
        if(newPass != confirmPass){
            mui.toast("两次密码不一致");
            return;
        }

        $.ajax({
            type: "post",
            url: "/user/updatePassword",
            data: {
                oldPassword : originPass,
                newPassword : newPass,
                vCode : vCode
            },
            success: function (res) {
                console.log(res);
                if(res.success){
                    mui.toast("修改成功");
                    location.href = "login.html";
                }else {
                    mui.toast("修改失败");
                }
            }
        });
    });

    $("#getCode").on("tap",function(){
        if($("#getCode").hasClass("doing")){
            return;
        }
        $(this).addClass("doing");
        $(this).text("正在请求...");
        var _this = this;
        setTimeout(function(){
            $(_this).removeClass("doing");
            $(_this).text("获取认证码");
        },2000);
        $.ajax({
            type: "get",
            url: "/user/vCodeForUpdatePassword",
            success: function (res) {
                console.log(res);
            }
        });
    });

});